<!DOCTYPE html>
<html>
    <head>
        <title>安和寿--医生查找</title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

        <meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
              ">

        <link rel="stylesheet" href="${basePath}/css/weui.min.css">
        <link rel="stylesheet" href="${basePath}/css/jquery-weui.css">
        <link rel="stylesheet" href="${basePath}/css/demos.css">

    </head>

    <body ontouchstart>
        <div class="weui-search-bar" id="searchBar">
            <div class="weui-search-bar__form">
                <div class="weui-search-bar__box">
                    <i class="weui-icon-search"></i>
                    <input type="search" class="weui-search-bar__input" id="searchInput" placeholder="搜索" required="" onsearch="search()">
                    <a href="#" class="weui-icon-clear" id="searchClear"></a>
                </div>
                <label class="weui-search-bar__label" id="searchText" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
                    <i class="weui-icon-search"></i>
                    <span>搜索</span>
                </label>
            </div>
            <a href="#" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
        </div>


        <div class="weui-cell weui-cell_select weui-cell_select-after">
            <div class="weui-cell__hd">
                <label for="" class="weui-label" style="width: 60px;">科室：</label>
            </div>
            <div class="weui-cell__bd">
                <select class="weui-select" name="select2" id="parentSelect" onchange="parentChange();">
                    <option value="0">全部</option>
                    <#list depts as dept>
                    <option value="${dept.id}"
                            <#if dept.id=deptSelected>
                            selected
                            </#if> 
                            >${dept.name}</option>
                    </#list>     
                </select>
            </div>
            <div class="weui-cell__bd" id="childDiv" style="display:none;">
                <select class="weui-select" name="select2" id="childSelect" onchange="childChange();">
                    <option value="0">全部</option>
                </select>
            </div>
        </div>

        <div class="page__bd">
            <div class="weui-panel weui-panel_access">
                <div class="weui-panel__bd" id="specialDiv">
                    <a href="javascript:addSpecial();">
                        <h1 class="demos-title" style="font-size: 16px;margin: 0 10px;text-align: right;">特约医生</h1>
                    </a>
                </div>
                <div class="weui-panel__bd" id="doctorList">
                </div>
                <div class="weui-panel__ft" id="viewMoreDiv">
                    <a href="javascript:viewMore();" class="weui-cell weui-cell_access weui-cell_link">
                        <div class="weui-cell__bd">查看更多</div>
                        <span class="weui-cell__ft"></span>
                    </a>    
                </div>
            </div>
        </div>

        <script src="${basePath}/js/jquery-2.1.4.js"></script>
        <script src="${basePath}/js/fastclick.js"></script>
        <script>
                    var type = "${type!}";
                    var LOCK=false;
                    var pageSize=10;
                    var viewPage=1;
                    var loadDoctors;
                    $(function () {
                        $("#viewMoreDiv").hide();
                        FastClick.attach(document.body);
                        if (parseInt(type) == 0) {
                            $('#searchText').trigger("click");
                            $("#searchInput").focus();
                        } else {
                            parentChange();
                        }
                    });
                    function search(){
                        LOCK=true;
                        var search = $("#searchInput").val();
                        $("#parentSelect").val("0");
                        $("#childDiv").hide();
                        $.ajax({
                            type: "post",
                            async: false,
                            url: '${basePath}/search.json',
                            contentType: "application/x-www-form-urlencoded; charset=utf-8",
                            data: {
                                search: search
                            },
                            success: function (data) {
                                dealData(data);
                            }
                        });
                        LOCK=false;
                    }
                    function parentChange(){
                        var parentId= $("#parentSelect").val();
                        $("#searchInput").val("");
                        $.ajax({
                            type: "post",
                            async: false,
                            url: '${basePath}/getChildDept.json',
                            contentType: "application/x-www-form-urlencoded; charset=utf-8",
                            data: {
                                parentId: parentId
                            },
                            success: function (data) {
                                if(data.result){
                                    var children=data.t;
                                    if(children!=null&&children.length>0){
                                        $("#childDiv").show();
                                        var text='<option value="0">全部</option>';
                                        for(var i= 0;i<children.length; i++){
                                            var child=children[i];
                                            text+='<option value="'+child.id+'">'+child.name+'</option>';
                                        }
                                        $("#childSelect").html(text);
                                    }else{
                                        $("#childDiv").hide();
                                    }
                                }
                            }
                        });
                        $.ajax({
                            type: "post",
                            async: false,
                            url: '${basePath}/listByDept.json',
                            contentType: "application/x-www-form-urlencoded; charset=utf-8",
                            data: {
                                parentId: parentId,
                                childId:0
                            },
                            success: function (data) {
                                dealData(data);
                            }
                        });
                    }
                    function childChange(){
                        $("#searchInput").val("");
                        var parentId= $("#parentSelect").val();
                        var childId= $("#childSelect").val();
                        $.ajax({
                            type: "post",
                            async: false,
                            url: '${basePath}/listByDept.json',
                            contentType: "application/x-www-form-urlencoded; charset=utf-8",
                            data: {
                                parentId: parentId,
                                childId:childId
                            },
                            success: function (data) {
                                dealData(data);
                            }
                        });
                    }
                    function dealData(data) {
                        viewPage=0;
                        var doctors=data.t;
                        loadDoctors=doctors;
                        var text = "";
                        var doctorSize=doctors.length;
                        viewPage++;
                        var viewSize=viewPage*pageSize;
                        if(viewSize>=doctorSize){
                            $("#viewMoreDiv").hide();
                            viewSize=doctorSize;
                        }else{
                            $("#viewMoreDiv").show();
                        }
                        if(doctorSize==0){
                            text='<div><h1 class="demos-title" style="font-size: 24px;color: #798DA5;">暂无数据</h1></div>';
                            $("#doctorList").html(text);
                        }else{
                            for (var i = 0; i < viewSize; i++) {
                                var doctor = doctors[i];
                                text += '<a href="javascript:detailDoctor('+doctor.id+');" class="weui-media-box weui-media-box_appmsg">' +
                                        '<div class="weui-media-box__hd">' +
                                        '<img src="${basePath}/icon.img?doctorId='+doctor.id+'" alt="" style="width:65px;height:90px;">' +
                                        '</div>' +
                                        '<div class="weui-media-box__bd">' +
                                        '<h4 class="weui-media-box__title">' +
                                        '<strong>'+doctor.name+'</strong>'+doctor.departmentName+' '+doctor.titleName +
                                        '</h4>' +
                                        '<p class="weui-media-box__desc"><span class="hospital">'+doctor.hospital+'</span></p>' +
                                        '<p class="weui-media-box__desc">'+doctor.good+'</p>' +
                                        '</div>' +
                                        '</a>';
                            }
                            $("#doctorList").html(text);
                        }
                    }
                    function viewMore(){
                        var doctorSize=loadDoctors.length;
                        var viewStart=viewPage*pageSize;
                        viewPage++;
                        var viewSize=viewPage*pageSize;
                        if(viewSize>=doctorSize){
                            $("#viewMoreDiv").hide();
                            viewSize=doctorSize;
                        }else{
                            $("#viewMoreDiv").show();
                        }
                        var text="";
                        for (var i = viewStart; i < viewSize; i++) {
                            var doctor = loadDoctors[i];
                            text += '<a href="javascript:detailDoctor('+doctor.id+');" class="weui-media-box weui-media-box_appmsg">' +
                                    '<div class="weui-media-box__hd">' +
                                    '<img src="${basePath}/icon.img?doctorId='+doctor.id+'" alt="" style="width:65px;height:90px;">' +
                                    '</div>' +
                                    '<div class="weui-media-box__bd">' +
                                    '<h4 class="weui-media-box__title">' +
                                    '<strong>'+doctor.name+'</strong>'+doctor.departmentName+' '+doctor.titleName +
                                    '</h4>' +
                                    '<p class="weui-media-box__desc"><span class="hospital">'+doctor.hospital+'</span></p>' +
                                    '<p class="weui-media-box__desc">'+doctor.good+'</p>' +
                                    '</div>' +
                                    '</a>';
                        }
                        $("#doctorList").append(text);
                    }
                    
                    function detailDoctor(id){
                        location.href = "${basePath}/detail.htm?doctorId="+id;
                    }
            function addSpecial(){
                location.href="${basePath}/special.htm";
            }

        </script>
        <script src="${basePath}/js/jquery-weui.js"></script>

    </body>
</html>
